package demo.sys.web;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import demo.Result;
import demo.common.web.BaseController;
import demo.sys.entity.User;

@Controller
public class LoginController extends BaseController {

	@ResponseBody
	@RequestMapping(value = "${adminPath}")
	public Result index(HttpServletRequest request) {
		Result result = new Result();
		result.setMsg("This is a test message.");
		return result;
	}
	
	@ResponseBody
	@RequestMapping(value = "${adminPath}/login")
	public Result login(HttpServletRequest request, @RequestBody User user) {
		Result result = new Result();
		
//		String loginName = request.getParameter("loginName");
//		String password = request.getParameter("password");
		if ("admin".equals(user.getLoginName()) &&
				"123456".equals(user.getPassword())) {
			result.setData(user);
		} else {
			result.setCode(500); // 这个地方的 500 有待商榷
			result.setMsg("用户名或密码错误！");
		}
		
		return result;
	}
}
